import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import { routerInit } from './util'
import { beforeEach } from './hook'

const Home = () => import(/* webpackChunkName: "Home" */ '@/views/home.vue')
const User = () => import(/* webpackChunkName: "User" */ '@/views/user.vue')
const TodoList = () => import(/* webpackChunkName: "TodoList" */ '@/views/todoList.vue')

const routes: RouteRecordRaw[] = [
  routerInit('/', 'TodoList', TodoList, 'todo-list'),
  routerInit('/home', 'home', Home, '首页'),
  routerInit('/user', 'user', User, '个人中心'),
]

const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior () {
    return { top: 0}
  }
})

beforeEach(router)

export default router